package 查看线程状态;

/**
 * 线程状态：
 * 1.new  新建状态
 * 2.runnable  运行状态
 * 3.timedWaiting  休眠状态
 * 4.terminated 终止状态
 * 5.waiting 等待
 * 6.blocked 受阻状态
 */
public class ThreadState extends Thread {
    @Override
    public void run() {
        while (true ){
            System.out.println("我是守护线程");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
     /*  int i=0;
        while (true ){
            i++;
            if (i%10000==0){
                try {
                    System.out.println("state=>"+getState());
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if(i>1e4)break;//10的100次方
        }*/
    }
    public static void main(String[] args){
        ThreadState ts=new ThreadState();
        System.out.println("new =>"+ts.getState());
        ts.start();
        System.out.println("start=>"+ts.getState());
        while (true){
            if (ts.isAlive()){
                System.out.println("main=>"+ts.getState());
            }
            else {
                System.out.println("*****=>"+ts.getState());
                break;
            }
        }
    }
}
